<template>
    <el-dialog title="审核" :visible.sync="showDialog" width="30%">
        <el-form :model="form" :rules="rules" ref="form">
            <el-form-item label="审核状态" prop="auditStatus">
                <el-radio-group v-model="form.auditStatus">
                    <el-radio :label="1">通过</el-radio>
                    <el-radio :label="0">拒绝</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="审核意见" prop="remark">
                <el-input type="textarea" v-model="form.remark" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="下推用户" prop="auditPerson" style="flex: 0 0 50%" v-if="rowFlowStatus!=4">
                <el-select v-model="form.auditPerson" filterable placeholder="请选择下推用户">
                    <el-option v-for="(item, index) in adminList" :key="index" :label="item.userName"
                        :value="item.userName">
                    </el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="close">取 消</el-button>
            <el-button type="primary" :disabled="loading" @click="submit">确 定</el-button>
        </span>
    </el-dialog>
</template>
<script>
import { audit } from "@/api/system/record";
import { getAdminList } from "@/api/system/follow";
export default {
    name: "AuditDialog",
    data() {
        return {
            loading: false,
            form: {
                exceptionId: 0,
                auditStatus: 0,
                remark: ''
            },
            rowFlowStatus:null,
            showDialog: false,
            adminList: [],
            rules: {
                auditStatus: [{ required: true, message: '请选择审核状态', trigger: 'change' }],
            }
        }
    },
    methods: {
        show(exceptionId,flowStatus) {
            console.info('show',flowStatus)
            this.getAdminList();
            this.form.exceptionId = exceptionId;
            this.rowFlowStatus = flowStatus
            this.showDialog = true;
        },
        reset() {
            this.loading = false;
            this.form = {
                exceptionId: 0,
                auditStatus: 0,
                remark: ''
            };
        },
        close() {
            this.showDialog = false;
            this.reset();
        },
        submit() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.loading = true;
                    audit(this.form).then(res => {
                        if (res.code == 200) {
                            this.$message({
                                message: '审核成功',
                                type: 'success'
                            });
                            this.$emit('success');
                            this.close();
                        } else {
                            this.$message.error(res.msg);
                        }
                        this.loading = false;
                    }).catch(err => {
                        this.loading = false;
                    });
                }
            });
        },
        getAdminList() {
            let param = {
                pageNum: 1,
                pageSize: 10000,
            };
            getAdminList(param).then((res) => {
                this.adminList = res.rows ? res.rows : [];
            });
        },
    }
}
</script>